<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>

</head>
<body>
    <div class="x-nav">
        <div class="select" >
                <span class="layui-breadcrumb" style="padding-top: 5px;display: inline-block;">
                  <a href="javascript:void(0)">首页</a><a href="javascript:void(0)">系统管理</a><a><cite>菜单管理</cite></a>
                </span>
            <button class="select-on layui-btn layui-btn-sm" style="float: right;" data-type="add"><i class="layui-icon">&#xe608;</i>新增</button>
            <button class="layui-btn layui-btn-sm" id="refresh" style="float: right;" data-type="reload"><i class="layui-icon">ဂ</i></button>
        </div>
    </div>
    <div id="menuTree"></div>
</body>
<myfooter>
    <%--tree引用的其他的 layui 暂时没有做集成--%>
    <script type="text/javascript" src="${ctxStatic}/kitadmin/plugins/layuitree/layui.js" charset="utf-8"></script>
    <script>
        var queryUrl = "${ctx}/sysResource/treeData";
        var delUrl = "${ctx}/sysResource/deleteEntity";
        var saveUrl = "${ctx}/sysResource/findOne";

        var layout = [
            { name: '菜单名称', treeNodes: true, headerClass: 'value_col', colClass: 'value_col', style: 'width: 10%'},
            { name: 'url',headerClass: 'value_col', colClass: 'value_col', style: 'width: 10%',
                render: function(row) {
                    return '<div class="layui-table-cell laytable-cell-1-username">'+abbr(row.url,30)+'</div>'; //列渲染
                }
            }, { name: '类型',headerClass: 'value_col', colClass: 'value_col', style: 'width: 3%',
                render: function(row) {
                    return '<div class="layui-table-cell laytable-cell-1-username">'+(row.isButton=="1"?'按钮':'菜单')+'</div>'; //列渲染
                }
            }, { name: 'code',headerClass: 'value_col', colClass: 'value_col', style: 'width: 10%',
                render: function(row) {
                    return '<div class="layui-table-cell laytable-cell-1-username">'+(typeof(row.code)=="undefined"?'':row.code)+'</div>'; //列渲染
                }
            },{ name: '图标',headerClass: 'value_col', colClass: 'value_col', style: 'width: 5%',
                render: function(row) {
                    return '<div class="layui-table-cell laytable-cell-1-username"><i class="layui-icon">'+(typeof(row.iconCls)=="undefined"?'':row.iconCls)+'</i></div>'; //列渲染
                }
            }/*,{ name: '序号',headerClass: 'value_col', colClass: 'value_col', style: 'width: 5%',
                render: function(row) {
                    return '<div class="layui-table-cell laytable-cell-1-username"><i class="layui-icon">'+(typeof(row.orderNum)=="undefined"?'':row.orderNum)+'</i></div>'; //列渲染
                }
            }*/,{
                name: '操作',headerClass: 'value_col',colClass: 'value_col',style: 'width: 20%',
                render: function(row) {
                    var chil_len=row.children.length;
                    row.detail = saveUrl+'?id=' + row.id;
                    var str=
                        '<a class="layui-btn layui-btn-primary layui-btn-xs" onclick="layerDetail(\'查看\',\'' + row.detail + '\', 700, 450)"><i class="layui-icon">&#xe615;</i> 查看</a>' +
                        '<a class="layui-btn layui-btn-xs  layui-btn-normal" onclick="layerSave(\'编辑\',\'' + row.detail + '\', 700, 450)"><i class="layui-icon">&#xe642;</i> 编辑</a>'; //列渲染
                    if(chil_len==0){
                        str+='<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="layerDelCheck(\'' + delUrl + '\',\'' + row.id + '\', true);"><i class="layui-icon">&#xe640;</i> 删除</a>';
                    }
                    return str;
                }
            }
        ];

        var nodes ;
        $(document).ready(function() {
            $.ajax({
                type: 'POST',
                dataType : "json",
                url: queryUrl,
                async:false,
                success:function(data){
                    nodes=data;
                }
            });
        });

        layui.use(['tree', 'layer'], function() {
            var layer = layui.layer;
            var treeGird = layui.treeGird({
                elem: '#menuTree',
                nodes:nodes,
                spreadable: true, //设置是否全展开，默认不展开
               /* url: queryUrl,*/
                layout: layout
            });
            var $ = layui.$, active = {
                add: function () {
                    layerSave('添加菜单', saveUrl+"?1=1", 700, 450);
                },
                reload:function(){
                    location.reload();
                }
            }
            /*头部按钮和刷新按钮的点击触发*/
            $('.select .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</myfooter>
